<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>localStorage存储图片</title>
</head>
<body>
	<script>
		var src = "11.jpg";
		function set(key) {
			var img = document.createElement('img');
			img.addEventListener("load",function() {
				var imgCanvas = document.createElement("canvas"),
					imgContext = imgCanvas.getContext("2d");

				imgCanvas.width = this.width;
				imgCanvas.height = this.height;

				imgContext.drawImage(this,0,0,this.width,this.height);
				var imgAsDataURL = imgCanvas.toDataURL("image/png");
				try{
					localStorage.setItem(key,imgAsDataURL);
				} catch (e) {
					console.log("Storage failed : " + e);
				}
			},false);
			img.src = src;
		}
		function get(key) {
			var srcStr = localStorage.getItem(key);
			var imgObj = document.createElement("img");
			imgObj.src = srcStr;
			document.body.appendChild(imgObj);
		}
	</script>
</body>
</html>